<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?
require_once '../classes/ConnectionDB.php';
require_once '../classes/UtenteManager.php';
require_once '../classes/TestDataManager.php';
  if($_COOKIE["codiceUtente"]!=1)
      header("Location:../portal/manageErrors.php?lista=29*");
  else
  {
$connection = ConnectionDB::getInstance()->connectToDB();
$codiceUtente = $_COOKIE['codiceUtente'];
$result = UtenteManager::getInstance()->getUtente($connection, $codiceUtente);
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Report utenti</title>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/prototype.js" type="text/javascript"></script>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/scriptaculous/effects.js" type="text/javascript"></script>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/glassbox/glassbox.js" type="text/javascript"></script>
        <style type="text/css">
            @import url("../css/style.css");
            table{
                width: 100%;
            }

            #tableResults td{
                text-align: center;
            }


            #searchForm {
                padding-top: 3%;
                margin-left: -5px;
            }

            #searchFormCont
            {
                padding-left: 2%;
            }

            #navigator
            {
                font-size: 14px;
            }

        </style>
        <script type="text/javascript">
            path_to_root_dir = "../glassboxLatest/glassbox.2.0.0/";
            var listaUtenti;
            var numItem=8;
            var currentIndex=0;

            window.onload = function()
            {
                var searchForm = new GlassBox();
                searchForm.init( 'searchForm', '640px', '190px', 'hidden','',true, false);
                searchForm.ipos();
                searchForm.appear();

                var results = new GlassBox();
                results.init( 'results', '1040px', '460px', '','',true,false);
                results.ipos();
                results.appear();
            }

            function xXMLHttpRequest()
            {

                var client = null;
                if (window.XMLHttpRequest)
                {
                    client=new XMLHttpRequest();
                }
                // code for IE
                else if (window.ActiveXObject)
                {
                    client=new ActiveXObject("Microsoft.XMLHTTP");
                }

                return client;
            }

            function handlerRes()
            {
                if(this.readyState == 4 && this.status == 200)
                {
                    listaUtenti = new Array();
                    var resp = eval(this.responseText);
                    if(resp != null)
                    {
                        for(i=0; i<resp.length; i++)
                        {
                            listaUtenti[i] = resp[i];
                        }
                    }
                    manageNavigatore(0);

                }
                else if (this.readyState == 4 && this.status != 200)
                {
                    alert("error this.status : " + this.status );

                }
            }

            function find()
            {
                var client = xXMLHttpRequest();
                client.onreadystatechange = handlerRes;
                var username = document.getElementById('username').value;
                var nome = document.getElementById('nome').value;
                var cognome =document.getElementById('cognome').value;

                var param = "operation=findUser&username="+ username +
                    "&nome="+nome+
                    "&cognome="+cognome;
                client.open("POST", "nuovoOperatoreListener.php", true);
                client.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

                client.send(param);

            }

            function deleteUser(codice)
            {
                
                var client = xXMLHttpRequest();
                client.onreadystatechange = function(){
                    find();
                };
                var param = "operation=deleteUser&codice="+codice;

                client.open("POST", "nuovoOperatoreListener.php", true);
                client.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

                client.send(param);
            }

            function manageNavigatore(ind)
            {
                var tmp= new Array();

                var str="<table id='tableResults' cellpadding='5' border='1'>"
                    +"<tr>"
                    +"<th>Dettaglio</th>"
                    +"<th>Codice utente</th>"
                    +"<th>Username</th>"
                    +"<th>Data registrazione</th>"
                    +"<th>Nome</th>"
                    +"<th>Cognome</th>"
                    +"<th>Email</th>"
                    +"<th>Attivo</th>"
                    +"<th>Elimina</th>"
                    +"</tr>";
                var indCurrenct=0;
                while(indCurrenct<numItem)
                {
                    //                    alert("idn " + ind);
                    if(ind<listaUtenti.length)
                    {
                        tmp=listaUtenti[ind];

                        var strAttivo = "";
                        if(tmp.attivo==0)
                            strAttivo = "<input type='checkbox' name='attivo' disabled />";
                        else
                            strAttivo = "<input type='checkbox' name='attivo' checked disabled/>";


                        str+="<tr>"+
                            "<td><a href='utente.php?codiceUtente="+tmp.codice+"'><img src='../images/icons/PNG/Magnifying Glass.png' height='30' width='30' title='Dettaglio' border='0'/></a></td>"+
                            "<td>"+tmp.codice+"</td>"+
                            "<td>"+tmp.username+"</td>"+
                            "<td>"+tmp.dataRegistrazione+"</td>"+
                            "<td>"+tmp.nome+"</td>"+
                            "<td>"+tmp.cognome+"</td>"+
                            "<td>"+tmp.email+"</td>"+
                            "<td>"+strAttivo+"</td>"+
                            "<td><input type='button' value='Elimina' onclick='javascript:deleteUser("+tmp.codice+")'/></td></tr>";
                    }
                    ind++;
                    indCurrenct++;
                }
                str +="</table>";
                var numTotItem = listaUtenti.length;
                var numPag = Math.ceil(numTotItem / numItem);
                if(numPag > 1)
                {
                    str +="<div id='navigator'><center>";
                    var current = 0;
                    var toPrint=1
                    for(k=1;k<=numPag;k++)
                    {
                        str+="<a href='javascript:manageNavi("+current+")'>"+toPrint+"</a>&nbsp;&nbsp;";
                        current= k * numItem;
                        toPrint = toPrint+1;
                    }
                    str+="</center></div>";
                }
                document.getElementById('resultsCont').innerHTML=str;
            }

            function showDetail(codice)
            {
                location.href="detailQuestion.php?codiceDomanda=" + codice;
            }
        </script>
    </head>
    <body>

        <?php include '../portal/header.php'; ?>
        <center>
            <div id="searchForm">
                <div id="searchFormCont">
                    <table>
                        <tr>
                            <td>Username:</td>
                            <td><input type="text" id="username" name="username" /></td>
                        </tr>

                        <tr>
                            <td>Nome:</td>
                            <td><input type="text" id="nome" name="nome" /></td>
                        </tr>

                        <tr>
                            <td>Cognome:</td>
                            <td><input type="text" id="cognome" name="cognome" /></td>
                        </tr>

                        <tr>
                            <td colspan="2">&nbsp;</td>
                            <td>
                                <input type="button" value="Cerca" onclick="find();" />
                            </td>
                        </tr>


                    </table>
                </div>
            </div>
            <div id="results"><div id="resultsCont"></div></div>
        </center>
    </body>
</html>
<?}?>
